﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FourSquareAPI;

namespace FourSquareWM
{
    public partial class formSearch : Form
    {
        private FourSquare FourSquareConn;
        public formSearch(FourSquare f)
        {
            InitializeComponent();
            this.FourSquareConn = f;
        }

        private void menuItemOk_Click(object sender, EventArgs e)
        {
           if(menuItemOk.Text == "Search")
           {
                this.listViewResults.Items.Clear();
                this.listViewResults.Items.Add(new ListViewItem("Searching..."));
                List<venue> venues = FourSquareConn.SearchVenues(38.895111,77.036667,textBox1.Text);
                this.listViewResults.Items.Clear();
                foreach(venue v2 in venues)
                {
                    ListViewItem venue = new ListViewItem();
                    venue.Text = v2.Name;
                    venue.Tag = v2;
                    this.listViewResults.Items.Add(venue);
                }
            }
        }

        private void menuItemCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        void listViewResults_ItemActivate(object sender, System.EventArgs e)
        {  
            ListView item = (ListView)sender;
            venue v = (venue)item.FocusedItem.Tag;
            new formCheckIn(FourSquareConn,v).Show();
            this.Close();
        }
    }
}